import 'package:flutter/material.dart';
import 'package:flutter_yn_goods/base/controller/base_list_more_controller.dart';
// import 'package:flutter_yn_goods/pages/agent_order_list/model/model_user_want.dart';
import 'package:flutter_yn_goods/pages/model/model_user_want.dart';
import 'package:flutter_yn_goods/utils/http/http_export.dart';
import 'package:flutter_yn_goods/utils/loading/loading_utils.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class AgentOrderListLogic extends BaseListMoreController {
  // final RefreshController refreshController = RefreshController();
  // final ScrollController scrollController = ScrollController();
  // final RxList<ModelUserWant> orderList = <ModelUserWant>[].obs;
  // final RxBool isLoading = false.obs;
  // final RxBool hasError = false.obs;
  // final RxString errorMsg = ''.obs;
  // final RxBool canLoadMore = true.obs;
  // final RxInt currentPage = 1.obs;
  // final int pageSize = 10;

  @override
  void onInit() {
    super.onInit();
    // fetchOrderList(isRefresh: true);
  }

  @override
  void onClose() {
    // refreshController.dispose();
    // scrollController.dispose();
    super.onClose();
  }

  @override
  Future<List> loadData() async {
    final response = await HttpManager().get(
      API.getWantList,
      params: {
        'page': pageNum,
        'limit': pageSize,
      },
      fromJson: ModelUserWant.fromJson
    );
return response.data ??[];
    if (response.isSuccess && response.data != null) {
      List<ModelUserWant> orders = [];
      if (response.data is List) {
        for (var item in response.data) {
          orders.add(ModelUserWant.fromJson(item));
        }
      } else if (response.data is Map) {
        var dataMap = response.data as Map;
        if (dataMap.containsKey('list') && dataMap['list'] is List) {
          for (var item in dataMap['list']) {
            orders.add(ModelUserWant.fromJson(item));
          }
        }
      }
      return orders;
    }
    
    return [];
  }
}
